#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k)
    {
        int left = 0, right = 0;
        deque<int> deq;
        vector<int> ret;

        for (; right < k; right++)
        {
            while (!deq.empty() && deq.back() < nums[right])
            {
                deq.pop_back();
            }
            deq.push_back(nums[right]);
        }
        ret.push_back(deq.front());

        for (; right < nums.size(); right++)
        {
            while (!deq.empty() && deq.back() < nums[right])
            {
                deq.pop_back();
            }
            deq.push_back(nums[right]);
            if (deq.front() == nums[left]) deq.pop_front();
            left++;
            ret.push_back(deq.front());

        }
        return ret;
    }
};